<!--
 * @Description: 干部等次
 * @Author: oooh
 * @Date: 2024-04-26 11:16:35
 * @LastEditors: hujunjie hujunjie@shudatech.cn
 * @LastEditTime: 2025-02-14 20:27:46
 * @FilePath: \Civil_Servant_Performance_PC\src\views\work-approval\cadre-assessment-grades\index.vue
-->
<template>
  <div class="app-container">
    <el-row>
      <el-col>
        <el-select v-model="queryParams.year" placeholder="选择年份" @change="handleYearChange">
          <el-option v-for="item in dict.type.biz_work_year_list" :key="item.value" :label="item.label" :value="item.value"> </el-option>
        </el-select>
      
        <el-cascader
          class="ml-10"
          v-model="queryParams.deptId"
          :options="deptOptions"
          :show-all-levels="false"
          :props="{ checkStrictly: true, value: 'deptId', label: 'deptName', checkStrictly: true, emitPath: false }"
          placeholder="选择站办所"
          filterable
          clearable
          @change="handleDeptChange"
          ref="CascaderRef"
        ></el-cascader>
      </el-col>
    </el-row>
    <div class="text-banner" style="flex-shrink: 0">
      <span>干部年度绩效考评等次</span>
      <el-button size="mini" type="primary" circle icon="el-icon-refresh" plain @click="handleRefresh" />
    </div>
    <div class="flex justify-between" v-hasPermi="['approval:cadre-assessment-grades:submit']" style="margin-bottom:10px">
      <div>
        <span style="font-size: 14px">批量设定：</span>
        <el-button
          size="mini"
          type="primary"
          plain
          :disabled="!selectionList.length"
          @click="handleGrade(item)"
          v-for="item in dict.type.biz_personal_year_performance_grade"
          :key="item.value"
          >{{ item.label }}</el-button
        >
      </div>
      <div>
        <el-button
          class="ml-10"
          icon="el-icon-s-claim"
          size="mini"
          type="warning"
          plain
          @click="handleSaveOrSubmit('save')"
          >保存</el-button
        >
      </div>
    </div>
    <div class="table">
      <el-table
        :data="tableList"
        border
        style="width: 100%"
        height="100%"
        ref="table"
        header-cell-class-name="table-header"
        v-loading="loading"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection"> </el-table-column>
        <el-table-column label="序号" type="index" align="center">
          <template slot-scope="scope">
            <span>{{ scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="deptName" label="站办所" align="center"> </el-table-column>

        <el-table-column prop="civilServantName" label="姓名" align="center">
          <template slot-scope="scope">
            <el-popover placement="top-start" v-if="scope.row.deptManagerMark" trigger="hover">
              <div>
                <i class="el-icon-star-on color-primary"></i>
                <span class="ml-10"> {{ scope.row.deptName }}负责人</span>
              </div>
              <i slot="reference" class="el-icon-star-on color-primary"></i>
            </el-popover>
            <span>{{ scope.row.civilServantName }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="civilServantPositionDictName" width="120" label="职务" align="center"></el-table-column>
        <el-table-column prop="workNatureDict" width="120" label="编制" align="center">
          <template slot-scope="scope">
            <dict-tag :options="dict.type.biz_civil_servant_work_nature" :value="scope.row.workNatureDict"></dict-tag>
          </template>
        </el-table-column>
        <el-table-column prop="gradeDict" label="考评等次" width="180" align="center">
          <template slot-scope="scope">
            <span class="cell-warning"></span>
            <el-select v-model="scope.row.gradeDict" placeholder="选择考评等次">
              <el-option v-for="item in dict.type.biz_personal_year_performance_grade" :key="item.value" :label="item.label" :value="item.value"> </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="remarks" label="备注"  align="center">
          <template slot-scope="scope">
            <p class="pre-wrap align-left">{{ scope.row.remarks || '-' }}</p>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { list, rating as listSubmit, } from '@/api/work-approval/year-cadre-grades'
import { deptTreeSelect } from '@/api/system/user'
export default {
  name: 'year-cadre-grades',
  dicts: ['biz_work_year_list', 'biz_personal_year_performance_grade', 'biz_civil_servant_work_nature'],
  data() {
    return {
      columns: [],
      loading: false,
      quarterOptions: [],
      tableList: [],
      deptOptions: [],
      queryParams: {
        year: '',
        quarter: '',
        deptId: ''
      },
      selectionList: [],
      rankingRange: ''
    }
  },
  computed: {},
  watch: {},
  created() {
    ;(async () => {
      await this.getDeptTree()
      this.handleYearChange(new Date().getFullYear())
    })()
  },
  methods: {
  
   
    hasPermi(permi) {
      return this.$auth.hasPermi(permi)
    },
    handleGrade(raw) {
      for (let item of this.selectionList) {
        let index = this.tableList.findIndex(tableItem => tableItem == item)
        this.$set(this.tableList[index], 'gradeDict', raw.value)
      }
    },
    // 校验表格是否可选
    checkSelectable(raw, index) {
      let permi = this.$auth.hasPermiOr(['approval:cadre-assessment-grades:pass', 'approval:cadre-assessment-grades:reject'])
      if (permi) {
        return true
      } else {
        return !this.work.submitMark
      }
    },
    // 表格多选
    handleSelectionChange(selection) {
      this.selectionList = selection
    },

    /** 查询站办所下拉树结构 */
    async getDeptTree() {
      await deptTreeSelect().then(response => {
        this.deptOptions = this.removeEmptyChildren(response.data)
        // this.queryParams.deptId = this.deptOptions[0].deptId
      })
    },
    // 选择站办所
    handleDeptChange() {
      this.getList()
      this.$refs.CascaderRef.dropDownVisible = false
    },
    handleSaveOrSubmit(operation) {
      let params = this.tableList.map(item => {
        return { id: item.id, gradeDict: item.gradeDict ,remarks:item.remarks}
      })
      listSubmit(params).then(res => {
        if (operation === 'submit') {
          this.$modal.msgSuccess('已提交')
        } else if (operation === 'save') {
          this.$modal.msgSuccess('已保存')
        }
        this.handleRefresh()
      })
    },
    getList() {
      this.loading = true
      list(this.queryParams)
        .then(res => {
          this.loading = false
          this.tableList = res.data
        
          this.$refs['table'].doLayout()
        })
        .catch(err => (this.loading = false))
    },

    // 刷新
    handleRefresh() {
      this.getList()
    },
    // 年度选择
    handleYearChange(year) {
      this.queryParams.year = year
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
// ::v-deep .row-custom .cell-warning {
//   background-color: rgba(246, 133, 129, 0.48) !important;
// }
::v-deep .warning-row {
  background-color: rgba(246, 133, 129, 0.48);
  color: #ee2a0f;
  .el-input__inner {
    color: #ee2a0f;
  }
}
::v-deep .el-input__inner {
  background-color: transparent;
}
.el-input-number--medium {
  width: auto;
}
.app-container {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  .table {
    flex: 1;
    overflow-y: hidden;
  }
}
::v-deep .table-header .cell {
  white-space: pre-wrap;
}
</style>
